/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package packet.in;

import io.ByteReader;
import io.ByteWriter;
import packet.RtxOutPacket;

import java.io.IOException;

/**
 * Project  : packet.in
 * Author   : solosky < solosky772@qq.com >
 * Created  : 2014/10/9
 * License  : Apache License 2.0
 */
public class SendIMPacket extends RtxOutPacket {
    private int timestamp;
    private String imType;
    private String imType2;
    private String from;
    private String to;
    private String body;
    @Override
    public void pack(ByteWriter writer) throws IOException {
        writer.writeInt(0);
        writer.writeInt(timestamp);
        writer.writeUnicode(imType);
        writer.writeByte(0);
        writer.writeUnicode(imType2);
        writer.writeUnicode(from);
        writer.writeByte(0);
        writer.writeUnicode(to);
        writer.writeShort(0x01A8); //未知。。
        writer.writeUnicode2(body);
    }

    public void unpack(ByteReader reader) {
        reader.readInt();
        timestamp = reader.readInt();
        imType = reader.readUnicode();
        reader.readByte();
        imType2 = reader.readUnicode();
        from = reader.readUnicode();
        reader.readByte();
        to =reader.readUnicode();
        reader.readShort();
        body =reader.readUnicode2();
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    public void setImType(String imType) {
        this.imType = imType;
    }

    public void setImType2(String imType2) {
        this.imType2 = imType2;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return "SendIMPacket{" +
                "timestamp=" + timestamp +
                ", imType='" + imType + '\'' +
                ", imType2='" + imType2 + '\'' +
                ", from='" + from + '\'' +
                ", to='" + to + '\'' +
                ", body='" + body + '\'' +
                '}';
    }
}
